<template>
  <div>
    <FormNavbar
      :title="navbar_title"
      :buttons="buttons"
      :hasActive="hasActive"
      :editable="editable"
      :record="record"
      @click-left="onClickLeft"
      @click-right="onClickRight"
    />

    <OToolbar
      :editable="editable"
      :current-state="current_state"
      :states="header_statusbar_visible"
      :buttons="header_buttons"
      @button-clicked="handleBtnClicked"
    />

    <a-divider />

    <template v-if="!editable">
      <!-- 三个专用功能按钮 -->
      <template v-if="['in_invoice', 'in_refund'].includes(record.type)">
      </template>
      <template v-if="['out_invoice', 'out_refund'].includes(record.type)">
        <template v-if="['confirmed', 'doing', 'done'].includes(record.state)">
          <a-button
            v-if="record.fapiao_serial_num"
            size="small"
            @click="
              handleBtnClicked({ type: 'object', name: 'action_print_read' })
            "
          >
            已开票查询
          </a-button>
          <a-button
            v-else
            size="small"
            @click="handleBtnClicked({ type: 'object', name: 'action_print' })"
          >
            开票
          </a-button>
        </template>
      </template>
    </template>

    <div>
      <div>发票类型: {{ { ...record, ...values }.type }}</div>
      <div>订单号码: {{ { ...record, ...values }.name }}</div>
      <div>发票序列号: {{ record.fapiao_serial_num }}</div>
      <div>开票状态: {{ record.api_status }}</div>
      <div>开票状态: {{ record.api_status_msg }}</div>
      <div>开票失败原因: {{ record.api_fail_cause }}</div>

      <div>
        下载:
        <OField
          :field-info="{ ...meta_get('attachment_id') }"
          :view-info="viewInfo"
          :data-info="dataInfo"
        />
      </div>
    </div>

    <FapiaoPage
      ref="refForm"
      :model.sync="formValues"
      :rules="rules_edit"
      :editable="editable"
      :fields="fields"
      :view-info="viewInfo"
      :data-info="dataInfo"
      @change="handleChange"
    />
  </div>
</template>

<script>
import formMixin from '@/odooui/formMixin'
import FormNavbar from '@/components/ONavbar/formNavbar.vue'
import OToolbar from '@/components/OToolbar/index.vue'

import FapiaoPage from './fapiao_page.vue'

import OField from '@/components/OField/OField.vue'

export default {
  name: 'FormView',
  components: { FormNavbar, OToolbar, FapiaoPage, OField },

  mixins: [formMixin],

  props: {},

  data() {
    return {}
  },
  computed: {},

  watch: {},

  created() {},

  mounted() {},

  methods: {
    onClickLeft() {
      if (this.editable) {
        this.onClickCancel()
      } else {
        this.onClickBack()
      }
    },

    onClickRight(btn) {
      const btn_fns = {
        save: 'onClickSave',
        edit: 'onClickEdit',
        new: 'onClickNew',
        del: 'onClickDel',
        unlink: 'onClickDel',
        copy: 'handleOnCopy',
        archive: 'handleOnArchive',
        unarchive: 'handleOnUnarchive'
      }

      this[btn_fns[btn]]()
    }
  }
}
</script>

<style scoped></style>
